package cn.wolfcode.trip.base.domain;

import cn.wolfcode.trip.base.util.JSONUtil;
import com.fasterxml.jackson.annotation.JsonFormat;
import lombok.Getter;
import lombok.Setter;
import org.springframework.format.annotation.DateTimeFormat;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

@Setter
@Getter
public class StrategyComment extends BaseDomain {
    public static final int STATE_NORMAL = 0;
    public static final int STATE_STOP = -1;
    public static final int STATE_COMMEND = 1;

    private User user;
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date createTime;

    private String content;

    private String imgUrls;

    private Integer starNum;

    private Strategy strategy;

    private Long praiseNum;

    private Integer state = STATE_NORMAL;
    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
    @JsonFormat(pattern = "yyyy-MM-dd HH:mm:ss",timezone = "GMT+8")
    private Date commendTime;

    public String getStateName(){
        String temp = "正常";
        if(state == STATE_STOP){
            temp = "禁用";
        }else if(state == STATE_COMMEND){
            temp = "推荐";
        }
        return temp;
    }


    public String[] getImgs(){
        if(imgUrls!=null) {
            return imgUrls.split(";");
        }
        return null;
    }

    public String getJson(){
         Map<String,Object> map = new HashMap<>();
         if(user != null){
            map.put("authorId",user.getId());
         }
         map.put("id",id);
        return JSONUtil.toJSONString(map);
    }

}